home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lcppb.zip / LCPPANS.ZIP / GETVALS.CPP < prev    next >
C/C++ Source or Header  |  1991-07-08  |  1KB  |  50 lines

  1. // getvals.cpp -- Get values in ranges
  2.  
  3. #include <iostream.h>
  4.  
  5. void getValues(int &low, int &high, int min, int max);
  6. void getOneValue(const char *prompt, int &v, int min, int max);
  7.  
  8. main()
  9. {
  10.   int low, high;
  11.   getValues(low, high, 10, 50);
  12.   cout << "\nlow == " << low << " high == " << high;
  13. }
  14.  
  15. void getValues(int &low, int &high, int min, int max)
  16. {
  17.   int result;
  18.  
  19.   cout << "\nEnter two values between " << min << " and " << max;
  20.   cout << "\nThe first value must be less or equal to the second.";
  21.   do {
  22.     getOneValue("\nLow value?  ", low, min, max);
  23.     getOneValue("\nHigh value? ", high, min, max);
  24.     result = (low <= high);
  25.     if (result == 0)
  26.         cout << "\nERROR: Low value must be <= high.";
  27.   } while (result == 0);
  28. }
  29.  
  30. void getOneValue(const char *prompt, int &v, int min, int max)
  31. {
  32.   int result;
  33.  
  34.   do {
  35.     cout << prompt;
  36.     cin >> v;
  37.     result = (min <= v) && (v <= max);
  38.     if (result == 0)
  39.         cout << "\nERROR: value out of range";
  40.   } while (result == 0);
  41. }
  42.  
  43.  
  44. // Copyright (c) 1990 by Tom Swan. All rights reserved
  45. // Revision 1.00    Date: 12/04/1990   Time: 05:30 pm
  46.  
  47. // Revision 1.01    Date: 07/08/1991   Time: 05:41 pm
  48. // Converted for Borland C++ 2.0
  49.  
  50.